package com.athuiju.fenxiaoback.service.impl;

import com.athuiju.fenxiaoback.entity.OmsOrder;
import com.athuiju.fenxiaoback.entity.OmsOrderItem;
import com.athuiju.fenxiaoback.entity.PmsSkuSaleParamValue;
import com.athuiju.fenxiaoback.mapper.OmsOrderMapper;
import com.athuiju.fenxiaoback.service.OmsOrderItemService;
import com.athuiju.fenxiaoback.service.OmsOrderService;
import com.athuiju.fenxiaoback.service.PmsSkuSaleParamValueService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author athuiju
 * @since 2021-07-05
 */
@Service
public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper, OmsOrder> implements OmsOrderService {


    @Autowired
    OmsOrderItemService omsOrderItemService;


    @Autowired
    PmsSkuSaleParamValueService skuSaleParamValueService;


    @Override
    public List<OmsOrder> getOrders(List<OmsOrder> orders){
        for (int i=0;i<orders.size();i++){
            Long orderId = orders.get(i).getId();
            List<OmsOrderItem> items = omsOrderItemService.list(new QueryWrapper<OmsOrderItem>().eq("order_id", orderId));


            for (int j=0;j<items.size();j++){
                StringBuffer saleString=new StringBuffer("");
                Long skuId = items.get(j).getSkuId();
                List<PmsSkuSaleParamValue> saleList = skuSaleParamValueService.list(new QueryWrapper<PmsSkuSaleParamValue>().eq("sku_id", skuId).orderByAsc("param_id"));
                for (PmsSkuSaleParamValue sale : saleList) {
                    saleString.append(sale.getParamValue()+"  ");
                }
                items.get(j).setSkuAttrsVals(saleString.toString());
            }


            orders.get(i).setItemEntities(items);
        }
        return  orders;
    }

}
